package help

import (
	"fmt"
	"io"
	"os"
	"time"
)

func CopyFile(dst, src string) error {
	fDest, err := os.Create(dst)
	if err != nil {
		return err
	}

	defer fDest.Close()

	fSrc, err := os.Open(src)
	if err != nil {
		return err
	}

	defer fSrc.Close()

	_, _ = fDest.WriteString(time.Now().Format(time.RFC3339Nano))

	_, err = io.Copy(fDest, fSrc)
	if err != nil {
		return err
	}

	return nil
}

type CustomLogout struct {
	w io.Writer
}

func NewCustomLogout(w io.Writer) *CustomLogout {
	return &CustomLogout{w: w}
}

func (tis *CustomLogout) Write(p []byte) (n int, err error) {
	_, _ = fmt.Fprint(os.Stderr, string(p))
	return tis.w.Write(p)
}
